<template>
  <div>
    <edu-dialog :title="sendData.title" width="60%" :visible.sync="show" :autoHeight="true"
      :confirmBtnText="$t('common.btn.confirm')" :close-on-click-modal="false" @close="close"
      @confirm="confirm('studentForm')">
      <el-form :model="formInfo" ref="studentForm" :rules="rules" label-width="50px" label-position="right"
        size="small" @submit.native.prevent>
        <el-row type="flex" class="row-bg" justify="space-between">
            <el-col :span="10">
                <el-form-item label="学生" prop="keyWords">
                    <el-input v-model="formInfo.keyWords" @change="search" clearable/>
                </el-form-item>
            </el-col>
            <div>
              <el-button @click='reset'>{{$t('common.btn.reset')}}</el-button>
              <el-button type="primary" @click='search'>{{$t('common.btn.filter')}}</el-button>
            </div>
        </el-row>
      </el-form>
      <edu-table :data="tableData" :order="false" @selection-change="checkBoxChange" :pageNum="page.pageNum_"
      :pageSize="page.pageSize_" :total="page.total" @page-change="pageChange" :pageSizes="[10, 20, 50, 100, 500, 1000]">
        <edu-table-column :label="$t('label.stuCode')"  prop="studentId"/>
        <edu-table-column :label="$t('label.stuName')" prop="name"/>
        <edu-table-column label="学院名称"  prop="facultyI18n"/>
        <edu-table-column  label="专业名称" prop="professionI18n"/>
        <edu-table-column  label="毕业类型" v-if="sendData.isNotGraduationStudent" width='100' prop="orginManualConclusionI18n" />
      </edu-table>
    </edu-dialog>
  </div>
</template>
<script>
  import {getDefaultQuery} from  'common/src/api/graduationManagement/graduationManage';
  export default {
    props: {
      show: {
        type: Boolean,
        default: false
      },
      sendData: {
        type: Object,
        default: {}
      }
    },
    data() {
      return {
        formInfo: {
          keyWords: '',
        },
        rules: {},
        tableData: [],
        page: {
          total: 0,
          pageNum_: 1,
          pageSize_: 10
        },
        multipleSelection: []
      }
    },
    created() {
      this.queryData();
    },
    methods: {
      search() {
        this.page.pageNum_ = 1;
        this.queryData();
      },
      reset() {
        this.$refs.studentForm.resetFields();
        this.page.pageNum_ = 1;
        this.queryData();
      },
      checkBoxChange(selection){
        this.multipleSelection = selection;
      },
      pageChange(val) {
        this.page.pageNum_ = val.pageNum;
        this.page.pageSize_ = val.pageSize;
        this.queryData();
      },
      queryData(){
        if (this.sendData.queryApi) {
          let param = {
            pageNum: this.page.pageNum_,
            pageSize: this.page.pageSize_,
            isOverseas: this.sendData.isOverseas,
            condition: this.formInfo.keyWords,
            graduationDate: this.sendData.graduationDate
          }
          this.sendData.queryApi(param).then(res =>{
            if (res && res.code === 200) {
              let data = res.data || {};
              this.tableData = data.list || [];
              this.page.total = data.total_;
            }
          })
        }
      },
      confirm() {
        if (!this.multipleSelection.length) {
          this.$message({
            message: '请选择学生',
            type: 'warning'
          });
        }else {
          let ids = _.map(this.multipleSelection, "studentId");
          let param = {
            studentIds: ids.join(',')
          };
          if (this.sendData.addApi) {
            this.sendData.addApi(param).then(res =>{
              this.close();
              this.$message({
                message: '添加学生成功',
                type: 'success'
              });
              this.sendData.updateList();
            })
          }
        }
      },
      close() {
        this.$refs.studentForm.resetFields();
        this.$emit('update:show', false);
      }
    }
  }

</script>
